<template>
  <Presentation ref="presentationRef" :data="formAdd" :rules="addFormRules" :items="addFormItems" :exclude="exclude"
    @submit="submit" />
</template>

<script lang="ts" setup>
import refComponent from '@/utils/refComponent';
import Presentation from '@/components/base/presentation.vue';

import { ref, reactive } from 'vue';
import { ElMessage } from 'element-plus';
import { packParams } from '@/utils/formUtil';
import { base, ${dv}, addFormItems, addFormRules } from '../ts/main';

const emit = defineEmits(['success']);
const formAdd = reactive<${dv}>(new ${dv}());
const exclude: Array<keyof ${dv}> = [${exclude}];
const presentationRef = refComponent(Presentation);

const submit = async () => {
  const res = await base.baseApi.insert(packParams(formAdd))
  if (res.isSuccess) {
    emit('success', res.data);
    ElMessage.success(res.message);
    presentationRef.value?.reset();
    presentationRef.value?.closeLoading();
  } else {
    ElMessage.error(res.message);
  }
}

</script>

<style lang="scss" scoped></style>